define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'orderpdd/index',
                    add_url: 'orderpdd/add',
                    edit_url: 'orderpdd/edit',
                    del_url: 'orderpdd/del',
                    multi_url: 'orderpdd/multi',
                    table: 'order_pdd',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                search: false,
                searchFormVisible: true,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'merid', title: __('Merid')},
                        {field: 'user_id', title: __('User_id')},
                        {field: 'order_sn', title: __('Order_sn')},
                        {field: 'goods_id', title: __('Goods_id')},
                        {field: 'goods_name', title: __('Goods_name')},
                        {field: 'goods_thumbnail_url', title: __('Goods_thumbnail_url'), formatter: Table.api.formatter.image},
                        {field: 'goods_quantity', title: __('Goods_quantity')},
                        {field: 'goods_price', title: __('Goods_price'), operate:'BETWEEN', formatter: function(value, row, index) {
                            return value/100;
                            }},
                        {field: 'order_amount', title: __('Order_amount'), operate:'BETWEEN', formatter: function(value, row, index) {
                                return value/100;
                            }},
                        {field: 'promotion_rate', title: __('Promotion_rate'), operate:'BETWEEN', formatter: function(value, row, index) {
                            return value/10+'%';
                            }},
                        {field: 'promotion_amount', title: __('Promotion_amount'), operate:'BETWEEN', formatter: function(value, row, index) {
                                return value/100;
                            }},
                        // {field: 'batch_no', title: __('Batch_no')},
                        {field: 'order_status', title: __('Order_status'), visible: false, searchList: Config.orderStatusList},
                        {field: 'order_status_desc', title: __('Order_status_desc')},
                        {field: 'order_create_time', title: __('Order_create_time'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {field: 'order_pay_time', title: __('Order_pay_time'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {field: 'order_group_success_time', title: __('Order_group_success_time'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {field: 'order_receive_time', title: __('Order_receive_time'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {field: 'order_verify_time', title: __('Order_verify_time'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {field: 'order_settle_time', title: __('Order_settle_time'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        // {field: 'order_modify_at', title: __('Order_modify_at')},
                        // {field: 'match_channel', title: __('Match_channel')},
                        // {field: 'verify_time', title: __('Verify_time'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {field: 'type_text', title: __('Type'), operate: false},
                        // {field: 'group_id', title: __('Group_id')},
                        // {field: 'auth_duo_id', title: __('Auth_duo_id')},
                        // {field: 'zs_duo_id', title: __('Zs_duo_id')},
                        {field: 'custom_parameters', title: __('Custom_parameters')},
                        // {field: 'duo_coupon_amount', title: __('Duo_coupon_amount'), operate:'BETWEEN'},
                        // {field: 'p_id', title: __('P_id')},
                        {field: 'status', title: __('Status'), visible: false, searchList: Config.statusList},
                        {field: 'status_text', title: __('Status'), operate: false},
                        // {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});